package com.tansun.easycare.rule.rulegroup.service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import com.tansun.easycare.core.utils.ResponseTable;
import com.tansun.easycare.rule.common.model.RuleSetParamInfo;
import com.tansun.easycare.rule.common.service.RuleBaseService;
import com.tansun.easycare.rule.common.web.model.ProjectInfo;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulegroup.entity.RuleEntry;
import com.tansun.easycare.rule.rulegroup.entity.RuleGroup;
import com.tansun.easycare.rule.rulegroup.entity.RuleGroupRef;
import com.tansun.easycare.rule.rulegroup.model.OldRuleGroupRefNew;
import com.tansun.easycare.rule.rulegroup.model.RuleEditEntity;
import com.tansun.easycare.rule.rulegroup.model.RuleEntryReq;
import com.tansun.easycare.rule.rulegroup.model.RuleGroupInfo;
import com.tansun.easycare.rule.rulegroup.model.RuleRefVOPage;
import com.tansun.easycare.rule.rulegroup.model.RuleSetDataInfo;
import com.tansun.easycare.rule.rulegroup.model.RuleSetVO;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;
import com.tansun.easycare.rule.rulemange.model.RuleManageVO;

public interface RuleGroupService extends RuleBaseService<RuleGroup> {

    /**
     * 规则集数据变量、域、操作符、值
     */
    String getRuleSetEditJson(RuleSetDataInfo ruleSetData) throws BizException;

    /**
     * 保存规则
     */
    void saveOrUpdate(RuleGroup ruleGroup) throws BizException;
    
    
    void saveOrUpdateRule(RuleManage ruleManage,RuleEditEntity ruleEditEntity) throws Exception;
    
    /**
     * 打开条目,获取条目信息
     */
    ResponseTable<RuleGroup> openRuleEntryView(RuleGroupInfo ruleGroupInfo) throws IllegalAccessException, InvocationTargetException;

    /**
     * 普通规则版本切换
     * @param ruleManage
     * @throws BizException
     */
    void updateGeneralRuleVersion(RuleManage ruleManage) throws BizException;
    /**
     * 保存复杂规则集，小版本更新
     */
    RuleManage saveOrUpdateRuleGroup(String manageId) throws BizException;
    
    /**
     * 保存简易规则集，小版本更新
     */
    void saveOrUpdateSimpleRuleGroup(String manageId) throws BizException;
    
    public OldRuleGroupRefNew copyComplexRuleGroup(String manageId,String oldVersion,String newVersion);
    
    /**
     * 修改顺序
     */
    void shiftSort(RuleManage ruleManage, String id1, String id2, String shiftType) throws BizException;

    /**
     * 编译drl
     */
    String compileDrl(String manageId) throws BizException;
    
    /**
     * 根据ruleManage获取drl
     * @param ruleManage
     * @return
     */
    public String getRuleDrl(RuleManage ruleManage);
    
    /**
     * 根据ruleManage获取drl
     * @param ruleManage
     * @return
     */
    public String getRuleDrl(String projectCode,String code);
    /**
     * 新增或修改规则
     */
    /**
     * 规则保存
     * @param ruleEditEntity
     * @throws Exception
     */
    public void saveOrUpdateRule(RuleEditEntity ruleEditEntity) throws Exception;
//    TestDataModeVO saveOrUpdateGeneralRule(RuleGroup ruleGroup) throws BizException;

    /**
     * 删除规则
     */
    void delGeneralRule(String manageId) throws BizException;

    /**
     * 显示DRL
     */
    String showRuleDrl(RuleSetVO ruleSetVO) throws Exception;
    
    /**
     * 显示Java
     */
    String showRuleJava(RuleSetVO ruleSetVO) throws Exception;
    
    /**
     * 显示Java
     */
    String showRuleJava(String manageId) throws Exception;

    /**
     * 查找普通规则
     */
    List<RuleGroup> generalRuleList(String projectCode) throws BizException;

    /**
     * 批量添加普通规则
     */
    RuleGroupRef addGroupRuleFromGerneal(String[] fromGeneral, String manageId, String entryId) throws BizException;

    /**
     * 复制普通规则
     */
    void copyRuleItem(RuleGroupInfo ruleGroupInfo) throws BizException;

    /**
     * 规则集本身复制
     */
    void copyRuleGroup(ProjectInfo projectInfo) throws Exception;
    
    /**
     *
     * @param currCode
     * @param projectCode
     * @return
     */
    List<RuleManageVO> findRuleGroupList(String currCode, String projectCode);

    /**
     * 规则转移
     */
    void transferRuleItem(String sourceRuleId, String sourceVersion, String targetCode, String projectCode) throws BizException;

    /**
     * 回退规则集
     */
    void returnRuleSetVersion(String manageId, String oldVersion) throws BizException;
    
    public  String   exportRuleExc(String projectCode,String  xml );
    
    public  void   makeInserMapJson(String projectCode);
    /**
     * 规则查询关联规则集条目
     * @param ruleRefVOPage
     * @return
     */
    public RuleRefVOPage findRuleReference(RuleRefVOPage ruleRefVOPage);
    
    /**
     * 规则生效后重新生成drl并保存
     * @param ruleIds
     * @param projectCode
     */
    public void updateRuleGoupDRL(List<String> ruleIds,String projectCode);
    
    /**
     * 查找规则的rulemanage
     * @param projectCode
     * @return
     * @throws BizException
     */
    public List<RuleSetVO> generalRuleSetVOList(String projectCode) throws BizException;
    
    /**
     * 查询规则生效版本，指当前项目中
     * @param ruleGroup projectCode
     * @return
     */
    List<RuleGroup> findEffectRuleList(RuleGroup ruleGroup);
    
    /**
     * 请求查询规则集条目信息，用于页面展示
     * @param ruleEntryReq
     * @param type
     * @return
     */
    public ResponseTable<RuleEntry> getEntryInfoByReq(RuleEntryReq ruleEntryReq,String type) throws Exception;

    
}
